

// ***Constants***
// Saucer States
#constant Spawning 0
#constant Dying    1
#constant Idle     2
#constant Moving   3
#constant Kicking  4
// Platforms
#constant pSmall    1
#constant pMedium   2
#constant pLarge    3
#constant MaxPlats  30
#constant pQSize    30
// Extended Floors
#constant eTopLeft   1
#constant eTopRight  2
#constant eBotLeft   3
#constant eBotRight  4
#constant eBaseLeft  5
#constant eBaseRight 6
// Spawn Queue
#constant Qsize 10
// Spawn info
#constant MaxSpawners 2
#constant SpawnDelay 1.0
// Enemy info
#constant MaxEnemies 3
// Input info
#constant BurstLeft  1
#constant BurstUp    2
#constant BurstRight 3
#constant RollLeft   4
#constant RollRight  5
// Type Definitions

type Saucer
    Sprite as integer
    Active as integer
    // Flags
    Direction as integer    // 1 = Right , 2 = Left
    MaxVel as float         // Set to 400 for player
    State as integer        // 0 = Spawning , 1 = Dying , 2 = Idle , 3 = Moving
    StateTimer as float     // Timer used for state transitions
    StateTimerGoal as float // When the timer is finished

    // AI only
    aiType as integer       // 0 = Player , 1 = Level 1 AI
    aiState as integer      // 0 = Idle , 1 = Patrol Zone , 2 = Seek Player
    Zone as integer         // 1 = Top , 2 = Middle , 3 = Bottom
    TargetX as integer
    TargetY as integer
endtype

type Platform
    // Sprites
    Sprite as integer
    Balloon1 as integer
    Balloon2 as integer
    String1 as integer
    String2 as integer
    // Flags
    State as integer        // 0 = Spawning , 1 = Dying , 2 = Idle
    StateTimer as float
    // Position
    TargetY as float
endtype

type PlatformQueue
    pType   as integer
    X       as integer
    Y       as integer
endtype

// Global Variables

// Arena
global arenaTimer as float
global g_iSky as integer
global g_iSkyImage as integer

// Platforms
global dim g_iPlatform      [ MaxPlats ] as Platform
global dim g_iPlatformImage [ 3 ] as integer
global dim g_iBalloonImage  [ 4 ] as integer
global g_iStringImage as integer
global dim g_iPlatformQueue [ pQSize ] as PlatformQueue

// Spawners
global dim g_iSpawner [ MaxSpawners ] as integer
global g_iSpawnerImage = 0
global dim g_iSpawnQueue [ QSize ] as integer
global g_iSpawnerTimer as float = timer()

// Player data
global pSaucer as Saucer
global dim g_iPlayerImage [ 6 ] as integer

// Enemy data
global dim eSaucer [ MaxEnemies ] as Saucer
global eSaucerImage = 0

// Other globals
global g_iGameState = 0
global thisFrame#
global difference#
global lastFrame#
global gameTimer#

// Debug Information
global DebugFile as integer
//DebugFile = OpenToWrite ( "Debug.txt", 0 )
if GetFileExists ( "Debug.txt" ) then DeleteFile ( "Debug.txt" )

// Includes
#include "arena.agc"
#include "player.agc"
#include "enemy.agc"
#include "misc.agc"
#include "input.agc"

// Start the game
SetErrorMode ( 2 )

Begin ( )


// main loop
do
    thisFrame# = Timer ( )
    difference# = thisFrame# - lastFrame#
    lastFrame# = thisFrame#

    gameTimer# = gameTimer# + difference#

    if g_iGameState = 0 then HandleMenu ( )
    if g_iGameState = 1 then HandleGame  ( )
    if g_iGameState = 2 then HandleEnd   ( )

    print ( str ( gameTimer# ) )


    // Update screen
    Sync ( )
loop

function Begin ( )
    // Landscape App
    SetVirtualResolution ( 1024, 768 )
    LoadAssets ( )
    SetJoystickScreenPosition   ( 80, 768 - 64, 128 )
    AddVirtualButton            ( 1, 1024 - 64, 768 - 64, 128 )
    lastFrame# = Timer ( )
    CreatePhysics ( )
    CreateArena   ( )
    //CreateMusic   ( )
endfunction

function HandleMenu ( )
    g_iGameState = 1
endfunction

function HandleGame ( )
    UpdateArena  ( )
    if pSaucer.Active = 1 then UpdatePlayer ( )
    for enemy = 1 to MaxEnemies
        if eSaucer [ enemy ].Active = 1 then UpdateEnemy ( enemy )
    next enemy
endfunction

function HandleEnd ( )

endfunction
